/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Supporter;
import javax.microedition.rms.*;
/**
 *
 * @author Mantero
 */
public class SaveLoadSupporter {
    public static RecordStore rs;
    public static void OpenRecordStore(String nameofstore) throws RecordStoreException
    {
        rs = RecordStore.openRecordStore(nameofstore, true);
    }
    public static int SaveRecord(String value) throws RecordStoreNotOpenException, RecordStoreException
    {
        byte[] bytearray = value.getBytes();
        int idreturn = rs.addRecord(bytearray, 0, bytearray.length);
        
        return idreturn;
    }
    public static String LoadRecord(int recordid) throws RecordStoreNotOpenException, InvalidRecordIDException, RecordStoreException
    {
        
        byte bytearray[] = rs.getRecord(recordid);
        System.out.println("loadrecord: "+recordid);
        String value = new String(bytearray);
        return value;
    }
    public static void DeleteRecord(int recordid) throws RecordStoreNotOpenException, InvalidRecordIDException, RecordStoreException
    {
        rs.deleteRecord(recordid);
    }
    public static void CloseRecordStore() throws RecordStoreNotOpenException, RecordStoreException
    {
        
        rs.closeRecordStore();
    }
    public static void UpdateRecord(int recordid, String value) throws RecordStoreNotOpenException, InvalidRecordIDException, RecordStoreException
    {
        byte bytearray[] = value.getBytes();
        rs.setRecord(recordid, bytearray, 0, bytearray.length);
    }
    public static void DeleteRecordStore() throws RecordStoreNotOpenException, RecordStoreException
    {
        RecordStore.deleteRecordStore(rs.getName());
    }
    public static int GetNumRecord() throws RecordStoreNotOpenException
    {
        int numofrecord=-1;
        if (rs!=null)
            numofrecord = rs.getNumRecords();
        return numofrecord;
    }
}
